# python数据基础第十一节：在网页搜集数据并将数据存储到DataFrame中
"""
python数据基础第十-节：在网页搜集数据并将数据存储到DataFrame中
    # 将数据添加到
    1、data = DataFrame(columns=["列1","列2"])
        data.append(
            Series(["数据1","数据2"],index=["列1","列2"]),ignore_index=True
        )

"""
# 导出数据的模块在DataFrame模块下
import json
import urllib.request

from pandas import Series
from pandas import DataFrame

from lxml import etree

response = urllib.request.urlopen('http://item.jd.com/1185291.html')

html = response.read()

resp = etree.HTML(html)

dts = resp.xpath('//*[@id="detail"]/div[2]/div[2]/div[1]/div[2]/dl/dt/text()')
dds = resp.xpath('//*[@id="detail"]/div[2]/div[2]/div[1]/div[2]/dl/dd/text()')

aa = zip(dts,dds)
data = DataFrame(columns=['Feature', 'Property'])

for dt,dd in aa :

    data = data.append(
        Series(
            [dt, dd],
            index=['Feature', 'Property']
        ), ignore_index=True
    )

len(data)

# 读取接口的价格json数据，肯那个有点问题
# response = urllib.request.urlopen('http://p.3.cn/prices/get?skuid=J_1185291')
# jsonString = response.read()
#
# jsonObject = json.loads(jsonString.decode())
#
# jsonObject[0]['p']
